// components/dark-mode/dark-mode.js
Component({
  properties: {
    isDarkMode: {
      type: Boolean,
      value: false,
    },
  },

  data: {
    isDarkMode: false,
  },

  lifetimes: {
    attached() {
      this.initDarkMode();
    },
  },

  methods: {
    initDarkMode() {
      const isDarkMode = wx.getStorageSync('isDarkMode') || false;
      this.setData({ isDarkMode });
      this.applyDarkMode(isDarkMode);
    },

    applyDarkMode(isDarkMode) {
      if (isDarkMode) {
        wx.setNavigationBarColor({
          frontColor: '#ffffff',
          backgroundColor: '#333333',
        });
      } else {
        wx.setNavigationBarColor({
          frontColor: '#000000',
          backgroundColor: '#ffffff',
        });
      }
    },
  },
});